#ifndef UTIL_ENCODING_H_
#define UTIL_ENCODING_H_
#include <string>
namespace yage {
namespace util {

/**
 * Functions to deal with Encoding under Win32
 * Any function does output strings MUST use functions provided below
 */

#ifdef _WIN32
wchar_t *ansi_to_utf_16(const char *str);
char *utf_16_to_ansi(const wchar_t *wstr);
wchar_t *utf_8_to_utf_16(const char *str);
char *utf_16_to_utf_8(const wchar_t *wstr);
#endif

/**
 * @author Shengyun Zhou (GGGZ-1101-28@live.cn)
 * @brief Check if the string is encoded with ASCII
 * @param str A C-style string.
 * @param str_length The length of the string.
 * @return Returns true if the string is encoded with ASCII.
 */
bool is_string_ASCII(const char *str, int str_length);

/**
 * @author Shengyun Zhou (GGGZ-1101-28@live.cn)
 * @brief Check if the string is encoded with UTF-8.
 * @param str A C-style string.
 * @param str_length The length of the string.
 * @return Returns true if the string is encoded with UTF-8.
 */
bool is_string_utf_8(const char *str, int str_length);

/**
 * @author Shengyun Zhou (GGGZ-1101-28@live.cn)
 * @brief Converts a string to a new string which is encoded with UTF-8.
 * @param str The string to be converted.
 * @return The new string encoded with UTF-8.
 */
std::string convert_string(const std::string& str);

/**
 * Convert ANSI to UTF-8 under Win32, do nothing under other platforms
 * Use free_string to free strings generated by this function.
 *
 * @author Xiaodong Qi (qxd@bupt.edu.cn)
 * @param str C-style string encoded in ANSI
 * @return C-style string encoded in UTF-8
 * @see free_string
 */
char *ansi_to_utf_8(const char *str);

/**
 * Convert UTF-8 to ANSI under Win32, do nothing under other platforms
 * Use free_string to free strings generated by this function.
 *
 * @author Xiaodong Qi (qxd@bupt.edu.cn)
 * @param wstr C-style string encoded in UTF-8
 * @return C-style string encoded in ANSI
 * @see free_string
 */
char *utf_8_to_ansi(const char *wstr);

/**
 * Free string generated by functions above under Win32, do nothing under other platforms
 *
 * @author Xiaodong Qi (qxd@bupt.edu.cn)
 * @param str the C-style string that its memory should be freed
 * @see ansi_to_utf_8
 * @see utf_8_to_ansi
 *
 */
void free_string(char *str);

}
}

#endif // UTIL_ENCODING_H_
